﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace S7.Windows.Menu
{
    /// <summary>
    /// Interaction logic for AddItem.xaml
    /// </summary>
    public partial class EditMenuItem : Window
    {
        public EditMenuItem()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Thread thr = new Thread(new ThreadStart(() =>
                {
                    var items = from item in MenuItem.lstItems
                                where item.MenuItemID == MenuItem.currID
                                select item;
                    this.Dispatcher.Invoke(new ThreadStart(() =>
                        {
                            try
                            {
                                foreach (var item in Menus.lstMenus)
                                {
                                    cbCategories.Items.Add(item.MenuName);
                                }
                                tbName.Text = items.ToList()[0].MenuItemName;
                                tbPrice.Text = items.ToList()[0].MenuItemPrice.ToString();
                                tbDescription.Text = items.ToList()[0].MenuItemDescription;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                            }
                        }), null);
                }));
            thr.IsBackground = true;
            thr.Start();
        }

        private void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            // Open dialog
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // cbCategories.SelectedItem =
            // tbName.Text =
            // tbPrice.Text =
            // shof el open dialog hat5do fen
            // tbDescription.Text = 
        }
    }
}
